// pages/profileTab/mycourse/mycourse.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag: 1, //后台获取是否为导师
    tabs1: [{
      "tabName": "未完成",
      "id": "unfinished"
    },
    {
      "tabName": "已完成",
      "id": "finished"
    }
    ],
    tabs2: [{
      "tabName": "未完成",
      "id": "unfinished"
    },
    {
      "tabName": "已完成",
      "id": "finished"
    },
    {
      "tabName": "待接单",
      "id": "booking"
    }
    ],
    items: ['课程类型', '导 &nbsp;&nbsp;师', '段 &nbsp;&nbsp;位', '时 &nbsp;&nbsp;长', '价 &nbsp;&nbsp;格'],
    isChecked: "unfinished",
    status: 0,
    classList: [],
    openId: "",
    navigatorUrl: "../courseDetail2/courseDetail2?status=0&dataId=",
    time:''
  },

  // 获取进行中的课程列表
  getClassList(openId) {
    let that = this;
    if (that.data.isChecked === "unfinished") {
      that.setData({
        status: 0
      })
    } else if (that.data.isChecked === "finished") {    
      that.setData({
        status: 1
      })
    } else if (that.data.isChecked === "booking") {
      that.setData({
        status: 2
      })
    }
    console.log(that.data.status)
    app.globalData.currentStatus = that.data.status;
    console.log(app.globalData.currentStatus)
    wx.request({
      url: "https://www.enjoyyz.com:8443/yinzuo/mycourse",
      // method: 'POST',
      data: {
        openid: app.globalData.openid,
        status: that.data.status
      },
      success(res) {
        console.log(res,'mycourse');
        that.setData({
          classList: res.data
        })
        console.log(that.data.classList,'classList')
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.openId = options.id;
    this.getClassList(this.data.openId)
    //获取当前时间戳
    var timestamp = Date.parse(new Date());
    var flag;
    timestamp = timestamp / 1000;
    console.log("当前时间戳为：" + timestamp);
    if (app.globalData.userType=='学员')
       flag = 0;
    else if (app.globalData.userType == '导师'){
        flag = 1
    }
    this.setData({
      flag:flag
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  currentItem: function (e) {
    var that = this;
    var code = e.currentTarget.id;
    that.setData({
      isChecked: code
    });
    if (code === "unfinished") {
      that.setData({
        navigatorUrl: "../courseDetail2/courseDetail2?status=0&dataId="
      })
    } else if (code === "finished") {
      that.setData({
        navigatorUrl: "../courseDetail2/courseDetail2?status=1&dataId="
      })
    } else if (code === "booking") {
      that.setData({
        navigatorUrl: "../courseDetail3/courseDetail3?status=2&dataId="
      })
    }
    that.getClassList(that.data.openId)
  },

  getIndex: function(e) {
    console.log("获取到的下标信息为")
    app.globalData.courseIndex = e.currentTarget.dataset.index;
    console.log(app.globalData.courseIndex)
  }
})